package cn.source.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.DbRecord;
import cn.source.system.service.IDbRecordService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 数据备份记录Controller
 * 
 * @author sourcebyte.vip
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/db/record")
public class DbRecordController extends BaseController
{
    @Autowired
    private IDbRecordService dbRecordService;

    /**
     * 查询数据备份记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbRecord dbRecord)
    {
        startPage();
        List<DbRecord> list = dbRecordService.selectDbRecordList(dbRecord);
        return getDataTable(list);
    }

    /**
     * 导出数据备份记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "数据备份记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DbRecord dbRecord)
    {
        List<DbRecord> list = dbRecordService.selectDbRecordList(dbRecord);
        ExcelUtil<DbRecord> util = new ExcelUtil<DbRecord>(DbRecord.class);
        util.exportExcel(response, list, "数据备份记录数据");
    }

    /**
     * 获取数据备份记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dbRecordService.selectDbRecordById(id));
    }

    /**
     * 新增数据备份记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "数据备份记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbRecord dbRecord)
    {
        return toAjax(dbRecordService.insertDbRecord(dbRecord));
    }

    /**
     * 修改数据备份记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "数据备份记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbRecord dbRecord)
    {
        return toAjax(dbRecordService.updateDbRecord(dbRecord));
    }

    /**
     * 删除数据备份记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "数据备份记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dbRecordService.deleteDbRecordByIds(ids));
    }

    //压缩文件下载


}
